// pages/withdrawPage/withdrawPage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      total: options.total
    })
  },
  //  获取提现金额
  inputChange: function(e) {
    var that = this;
    this.setData({
      account: e.detail.value
    });
    console.log(that.data.total);
    console.log(that.data.account);
    if (parseFloat(that.data.account) > parseFloat(that.data.total)) {
      wx.showToast({
        title: '超出提现金额',
        icon: "none",
        duration: 2000,
      })
    }
    // console.log(this.data.account);
  },
  all: function(e) {
    var that = this;
    that.setData({
      account: that.data.total
    })
  },
  // 全部提现
  allWithdraw: function(e) {
    // var all = e.currentTarget.dataset.all;
    var that = this;

    // if (all == 1) {
    //   that.setData({
    //     account: that.data.total
    //   })
    // } else {

    // }
    if (parseFloat(that.data.account) > parseFloat(that.data.total)) {
      wx.showToast({
        title: "超出提现总金额",
        icon: "none",
        duration: 2000
      })
    }else if(that.data.account==undefined){
      wx.showToast({
        title: '请输入提现金额',
        icon: "none",
        duration: 2000
      })
    }
     else {
      wx.showModal({
        title: '提示',
        content: '确定要提现' + that.data.account + "元",
        success: function(res) {
          if (res.confirm) {
            wx.request({
              url: 'https://www.xiaozheng8.com/money/record/out',
              data: {
                userId: wx.getStorageSync("userId"),
                money: -that.data.account
              },
              method: 'post',
              success: function(res) {
                wx.showToast({
                  title: '提现请求已提交',
                  icon: "success",
                  duration: 2000
                });
                wx.navigateBack({

                })

              },
              fail: function(res) {},
              complete: function(res) {},
            })
          }
        }
      })

    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})